$(function () {
    var itemIndex = 0;

    var tabLoadEndArray = [false, false, false];
    var tabLenghtArray = [28, 15, 47];
    var tabScroolTopArray = [0, 0, 0];
    
    var pageIndex1=0;
    var pageIndex2=0;
    // dropload
    var dropload = $('.khfxWarp').dropload({
        scrollArea: window,
        domDown: {
            domClass: 'dropload-down',
            domRefresh: '<div class="dropload-refresh">上拉加载更多</div>',
            domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
            domNoData: '<div class="dropload-noData">已无数据</div>'
        },
        loadDownFn: function (me) {
        /*	if (tabLoadEndArray[itemIndex]) {
                me.resetload();
                me.lock();
                me.noData();
                me.resetload();
                return;
            }*/
        	setTimeout(function () {
	        	var result = '';
	        	 if (itemIndex == 0 ) {
	        		 if(pageIndex1 <=pageSum){
	                $.ajax({
	                    type: 'POST',
	                    url: pth+'/resManage/showList',
	                    data:{id:pid,pageIndex:pageIndex1},
	                    dataType: 'json',
	                    success: function(data){
	                    	var json = eval(data);
	                    	
	                    	$.each(json, function (index, item) {
	                    		var record =new Object(); 
	                    		record.id=json[index].id;
	                          	record.time= json[index].time;
	                          	record.area=json[index].area;
	    	                   	record.address=json[index].address;
	    	                   	record.name=json[index].name;
	    	                   	record.phone=json[index].phone;
	    	                   	record.remark=json[index].reRemark;
	    	                
	    	                   	/*var result = '';*/
	                            result += ''
	    			            + ' <div class="nr-list"><span class="rid" style="display:none;">'+record.id+'</span>'
	    						+ ' 	<div class="nr-list-top">'
	    						+ ' 		<span class="times">'+getNowFormatDate(record.time)+'用车</span>'
	    						+ ' 		<a class="btnfs" href="javascript:void(0);" onclick="doCancel(this);" >取消</a>'
	    						+ ' 		<a class="btnfs" href="javascript:void(0);" onclick="finis(this);">完成</a>'
	    						+ ' 	</div>'
	    						+ ' 	<div class="nr-list-bot">'
	    						+ ' 		<p>'
	    						+ ' 		    <span>送车地址:</span>'
	    						+ ' 		    <span>'+record.area+'  '+record.address+'</span>'
	    						+ ' 		</p>'
	    						+ ' 		<p>'
	    						+ ' 		    <span>联&nbsp;系&nbsp;人:</span>'
	    						+ ' 		    <span>'+record.name+'</span>'
	    						+ ' 		</p>'
	    						+ ' 		<p>'
	    						+ ' 		    <span>联系电话:</span>'
	    						+ ' 		    <span class="phone">'+record.phone+'</span>'
	    						+ ' 		</p>'
	    						+ ' 		<p>'
	    						+ ' 		    <span>备&nbsp;&nbsp;&nbsp;&nbsp;注:</span>'
	    						+ ' 		    <span class="rem">'+record.remark+'</span>'
	    						+ ' 		</p>'
	    						+ ' 	</div>'
	    						+ ' </div>'
	    					  
	                           
	                    	});
	                    	$('.khfxPane').eq(itemIndex).append(result);
	                    	if(pageIndex1==pageSum){
	                    		// 每次数据加载完，必须重置
	                            me.lock();
	                            me.noData();
	                    	}
	                    	pageIndex1++;
	                       me.resetload();
	                       return;
	                    },
	                    error: function(xhr, type){
	                        alert('Ajax error!');
	                        // 即使加载出错，也得重置
	                        me.resetload();
	                    }
	                    
	                });
	        	 }else{
	        		 me.lock();
                     me.noData();
                     me.resetload();
                     return;
	        	 
	        	 	}	 
	        	 }else if (itemIndex == 1 ) {
	        		 if(pageIndex2 <=pageSum2){
	        		 $.ajax({
	                     type: 'POST',
	                     url: pth+'/resManage/showFinishList',
	                     data:{id:pid,pageIndex:pageIndex2},
	                     dataType: 'json',
	                     success: function(data){
	                     	var json = eval(data);
	                     	
	                     	$.each(json, function (index, item) {
	                     		var record =new Object(); 
	                     		record.id=json[index].id;
	                           	record.time= json[index].time;
	                           	record.area=json[index].area;
	     	                   	record.address=json[index].address;
	     	                   	record.name=json[index].name;
	     	                   	record.phone=json[index].phone;
	     	                	record.remark=json[index].reRemark;
	     	                   	
	     	                   	/*var result = '';*/
	                             result += ''
	     			            + ' <div class="nr-list">'
	     						+ ' 	<div class="nr-list-top">'
	     						+ ' 		<span class="times">'+getNowFormatDate(record.time)+'用车</span>'
	     						+ ''
	     						+ ' 	</div>'
	     						+ ' 	<div class="nr-list-bot">'
	     						+ ' 		<p>'
	     						+ ' 		    <span>送车地址:</span>'
	     						+ ' 		    <span>'+record.area+'  '+record.address+'</span>'
	     						+ ' 		</p>'
	     						+ ' 		<p>'
	     						+ ' 		    <span>联系人:</span>'
	     						+ ' 		    <span>'+record.name+'</span>'
	     						+ ' 		</p>'
	     						+ ' 		<p>'
	     						+ ' 		    <span>联系电话:</span>'
	     						+ ' 		    <span>'+record.phone+'</span>'
	     						+ ' 		</p>'
	     						+ ' 		<p>'
	    						+ ' 		    <span>备&nbsp;&nbsp;&nbsp;&nbsp;注:</span>'
	    						+ ' 		    <span class="rem">'+record.remark+'</span>'
	    						+ ' 		</p>'
	     						+ ' 	</div>'
	     						+ ' </div>'
	     					 
	                     	});
	                     	 $('.khfxPane').eq(itemIndex).append(result);   
	                     	if(pageIndex2==pageSum2){
	                    		// 每次数据加载完，必须重置
	                            me.lock();
	                            me.noData();
	                    	}
	                     	 pageIndex2++;
	                       me.resetload();
	                        return;
	                     },
	                     error: function(xhr, type){
	                         alert('Ajax error!');
	                         // 即使加载出错，也得重置
	                         me.resetload();
	                     }
	                     
	                 });
	        	 }else{
	        		 me.lock();
                     me.noData();
                     me.resetload();
                     return;
	        	 
	        	 }
	        	}
        	}, 1000);
        	 
          /*  setTimeout(function () {
                if (tabLoadEndArray[itemIndex]) {
                    me.resetload();
                    me.lock();
                    me.noData();
                    me.resetload();
                    return;
                }
                var result = '';
               
                for (index = 0; index <5; index++) {
                	var record =new Object(); 
               	 record.id=reList[index].id;
               	record.time=reList[index].time;
            	record.address=reList[index].address;
            	record.name=reList[index].name;
            	record.phone=reList[index].phone;
               	 record.createTime=json[index].ime;
                    if (tabLenghtArray[itemIndex] > 0) {
                        tabLenghtArray[itemIndex]--;
                    } else {
                        tabLoadEndArray[itemIndex] = true;
                        break;
                    }
                    if (itemIndex == 0) {
                        result
                        += ''
//                      + '    <hgroup class="khfxRow">'
//                      + '      <header>2015-10-18  23:32:13</header>'
//                      + '      <div class="mid">'
//                      + '        <img class="photo" src="images/img01.png" >'
//                      + '        <span><label>昵称：</label>弦上漫步</span> '
//                      + '        <span><label>账号：</label>' + tabLenghtArray[itemIndex] + '</span> '
//                      + '        <span><label>手机：</label>1391****746</span> '
//                      + '        <span><label>券商：</label>中信证券</span> '
//                      + '      </div>'
//                      + '      <footer><a href="#">提醒开户</a></footer>'
//                      + '    </hgroup>';
			            + ' <div class="nr-list">'
						+ ' 	<div class="nr-list-top">'
						+ ' 		<span>'+'用车</span>'
						+ ' 		<a class="btnfs" href="#">完成</a>'
						+ ' 	</div>'
						+ ' 	<div class="nr-list-bot">'
						+ ' 		<p>'
						+ ' 		    <span>送车地址:</span>'
						+ ' 		    <span>'+'</span>'
						+ ' 		</p>'
						+ ' 		<p>'
						+ ' 		    <span>联系人:</span>'
						+ ' 		    <span>'+'</span>'
						+ ' 		</p>'
						+ ' 		<p>'
						+ ' 		    <span>联系电话:</span>'
						+ ' 		    <span>'+'</span>'
						+ ' 		</p>'
						+ ' 	</div>'
						+ ' </div>'
                    }
//                  } else if (itemIndex == 1) {
//                      result
//                      += ''
//                      + '    <hgroup class="khfxRow">'
//                      + '      <header><span>已提交资料</span>2015-10-18  23:32:13</header>'
//                      + '      <div class="mid">'
//                      + '        <img class="photo" src="images/img01.png" >'
//                      + '        <span><label>昵称：</label>弦上漫步</span> '
//                      + '        <span><label>账号：</label>' + tabLenghtArray[itemIndex] + '</span> '
//                      + '        <span><label>手机：</label>1391****746</span> '
//                      + '        <span><label>券商：</label>中信证券</span> '
//                      + '      </div>'
//                      + '    </hgroup>';
//                  } else if (itemIndex == 2) {
//                      result
//                      += ''
//                      + '<hgroup class="khfxRow">'
//                      + '<header><span>已开户成功</span>2015-10-18  23:32:13</header>'
//                      + '<div class="mid">'
//                      + '<img class="photo" src="images/img01.png" >'
//                      + '<span><label>昵称：</label>弦上漫步</span> '
//                      + '<span><label>账号：</label>' + tabLenghtArray[itemIndex] + '</span> '
//                      + '<span><label>手机：</label>1391****746</span> '
//                      + '<span><label>券商：</label>中信证券</span> '
//                      + '</div>'
//                      + '</hgroup>';
//                  }
                }
                $('.khfxPane').eq(itemIndex).append(result);
                me.resetload();
            }, 500);*/
        }
    });


    $('.tabHead span ').on('click', function () {

        tabScroolTopArray[itemIndex] = $(window).scrollTop();
        var $this = $(this);
        itemIndex = $this.index();
        $(window).scrollTop(tabScroolTopArray[itemIndex]);
        
//      $(this).addClass('active').siblings('.tabHead span').removeClass('active');
//      $('.tabHead .border').css('left', $(this).offset().left + 'px');
     $('.khfxPane').eq(itemIndex).show().siblings('.khfxPane').hide();

        if (!tabLoadEndArray[itemIndex]) {
            dropload.unlock();
            dropload.noData(false);
        } else {
            dropload.lock('down');
            dropload.noData();
        }
        dropload.resetload();
    });
});